import axios from 'axios'
import commonUrl from '../common/js/commonUrl.js'
import { loadVillageId, loadOpenId } from '../common/js/cache.js'
import qs from 'qs'

// 物业报修列表数据
export function getRepairsData () {
  const url = `${commonUrl.apihost}index.php/home/repair/index/?areas_id=${loadVillageId()}`
  return axios({
    method: 'GET',
    url: url
  }).then((res) => {
    return Promise.resolve(res.data)
  }).catch((err) => {
    return Promise.reject(err)
  })
}

// 物业报修详情页面数据
export function getRepairsDetail (id) {
  const url = `${commonUrl.apihost}index.php/home/repair/getRepairDetail/?id=${id}`
  return axios({
    method: 'GET',
    url: url
  }).then((res) => {
    return Promise.resolve(res.data)
  }).catch((err) => {
    return Promise.reject(err)
  })
}

// 房屋租售列表通过微信jssdk 获取经纬度
export function getRentConfig () {
  const data = {
    url: window.location.href.split('#')[0]
  }
  return axios({
    method: 'POST',
    url: `${commonUrl.apihost}index.php/wx/wx_jssdk/getSignPackage`,
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
    },
    data: qs.stringify(data)
  }).then((res) => {
    return Promise.resolve(res.data)
  }).catch((err) => {
    return Promise.reject(err)
  })
}

// 房屋出租列表数据
export function getRentSaleData (code, lat, lng) {
  const url = `${commonUrl.apihost}index.php/home/renthouse/index/?district=${code}&lat=${lat}&lng=${lng}`
  return axios({
    method: 'GET',
    url: url
  }).then((res) => {
    return Promise.resolve(res.data)
  }).catch((err) => {
    return Promise.reject(err)
  })
}

// 房屋出租详情页面
export function getRentData (id) {
  const url = `${commonUrl.apihost}index.php/home/renthouse/getHouseDetail/?id=${id}`
  return axios({
    method: 'GET',
    url: url
  }).then((res) => {
    return Promise.resolve(res.data)
  }).catch((err) => {
    return Promise.reject(err)
  })
}

// 邻里求助列表数据
export function gethelpDetail () {
  const url = `${commonUrl.apihost}index.php/home/Neighbor/index?areas_id=${loadVillageId()}`
  return axios({
    method: 'GET',
    url: url
  }).then((res) => {
    return Promise.resolve(res.data)
  }).catch((err) => {
    return Promise.reject(err)
  })
}

// 邻里求助详情页面数据
export function getDetails (id) {
  const url = `${commonUrl.apihost}index.php/home/Neighbor/getNeighborDetail/?id=${id}`
  return axios({
    method: 'GET',
    url: url
  }).then((res) => {
    return Promise.resolve(res.data)
  }).catch((err) => {
    return Promise.reject(err)
  })
}

// 邻里闲置列表数据
export function getGoodsDetail () {
  const url = `${commonUrl.apihost}index.php/home/goods/index?areas_id=${loadVillageId()}`
  return axios({
    method: 'GET',
    url: url
  }).then((res) => {
    return Promise.resolve(res.data)
  }).catch((err) => {
    return Promise.reject(err)
  })
}

// 邻里闲置的详情页面数据
export function getDetail (id) {
  const url = `${commonUrl.apihost}index.php/home/goods/index/?id=${id}`
  return axios({
    method: 'GET',
    url: url
  }).then((res) => {
    return Promise.resolve(res.data)
  }).catch((err) => {
    return Promise.reject(err)
  })
}

// 我的发布列表数据
export function getMyIdle () {
  const url = commonUrl.apihost + 'index.php/home/personal/myPublish/?openid=' + loadOpenId()
  return axios({
    method: 'GET',
    url: url
  }).then((res) => {
    return Promise.resolve(res.data)
  }).catch((err) => {
    return Promise.reject(err)
  })
}

